dnd: Pass dx/dy instead of x_root/y_root
authorBenjamin Otte <otte@redhat.com>
Sun, 10 Dec 2017 23:55:56 +0000 (00:55 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 11 Dec 2017 00:02:31 +0000 (01:02 +0100)
This way, we don't need root coordinates when computing the dnd start
position.

gdk/broadway/gdkdnd-broadway.c
gdk/gdkdnd.h
gdk/gdkwindow.c
gdk/quartz/gdkdnd-quartz.c
gdk/wayland/gdkdnd-wayland.c
gdk/win32/gdkdnd-win32.c
gdk/x11/gdkdnd-x11.c
gtk/gtkdnd.c

index cbc1860181190d68d19857da3dff40dbc6e89fc6..ac11be4a2af1be5379a52dbb3fb0c40a061b12db 100644 (file)
@@ -87,8 +87,8 @@ GdkDragContext *
 _gdk_broadway_window_drag_begin (GdkWindow         *window,
                                 GdkDevice         *device,
                                 GdkContentFormats *formats,
-                                 gint               x_root,
-                                 gint               y_root)
+                                 gint               dx,
+                                 gint               dy)
 {
   GdkDragContext *new_context;
 
index f830fdc69e20d1097c0d961f897c3c31acc003c3..6d7d2244468afe67f6b3756b2f4665738a838b19 100644 (file)
@@ -137,8 +137,8 @@ GDK_AVAILABLE_IN_ALL
 GdkDragContext *        gdk_drag_begin                  (GdkWindow              *window,
                                                          GdkDevice              *device,
                                                          GdkContentFormats      *formats,
-                                                         gint                    x_root,
-                                                         gint                    y_root);
+                                                         gint                    dx,
+                                                         gint                    dy);
 
 GDK_AVAILABLE_IN_ALL
 gboolean        gdk_drag_drop_succeeded (GdkDragContext *context);
index d14558d72ab0f61c6298afb245d2a44b379c8f46..47ec729f2b9906e566c5a21bf05ab667a366f88f 100644 (file)
@@ -6928,8 +6928,8 @@ gdk_window_register_dnd (GdkWindow *window)
  * @window: the source window for this drag
  * @device: the device that controls this drag
  * @formats: (transfer none): the offered formats
- * @x_root: the x coordinate where the drag nominally started
- * @y_root: the y coordinate where the drag nominally started
+ * @dx: the x offset to @device's position where the drag nominally started
+ * @dy: the y offset to @device's position where the drag nominally started
  *
  * Starts a drag and creates a new drag context for it.
  *
index fc9c338ca2dec3e4f2096ba996f2b291e31a2e30..21438481b41a27fc2fba8b082be1a242ef754f4b 100644 (file)
@@ -36,8 +36,8 @@ GdkDragContext *
 _gdk_quartz_window_drag_begin (GdkWindow *window,
                                GdkDevice *device,
                                GList     *targets,
-                               gint       x_root,
-                               gint       y_root)
+                               gint       dx,
+                               gint       dy)
 {
   g_assert (_gdk_quartz_drag_source_context == NULL);
 
index b64f4877381fd3aaaf57193fb34b80a61db81bb8..ea1b6ef3a1a9238e960da20be6143884c360b0a5 100644 (file)
@@ -586,8 +586,8 @@ GdkDragContext *
 _gdk_wayland_window_drag_begin (GdkWindow         *window,
                                GdkDevice         *device,
                                GdkContentFormats *formats,
-                                gint               x_root,
-                                gint               y_root)
+                                gint               dx,
+                                gint               dy)
 {
   GdkWaylandDragContext *context_wayland;
   GdkDragContext *context;
index fbf5af6922f0257b9b56fa60079e91d3d4a55a6b..69528076226468c25fe8d29d6c99286f82923ab3 100644 (file)
@@ -2011,13 +2011,14 @@ GdkDragContext *
 _gdk_win32_window_drag_begin (GdkWindow         *window,
                               GdkDevice         *device,
                               GdkContentFormats *formats,
-                              gint               x_root,
-                              gint               y_root)
+                              gint               dx,
+                              gint               dy)
 {
   GdkDragContext *new_context;
   GdkWin32DragContext *context_win32;
   BYTE kbd_state[256];
   GdkWin32Selection *sel_win32 = _gdk_win32_selection_get ();
+  int x_root, y_root;
 
   if (!use_ole2_dnd)
     {
@@ -2050,6 +2051,10 @@ _gdk_win32_window_drag_begin (GdkWindow         *window,
       context_win32 = GDK_WIN32_DRAG_CONTEXT (new_context);
     }
 
+  gdk_device_get_position (device, &x_root, &y_root);
+  x_root += dx;
+  y_root += dy;
+
   context_win32->start_x = x_root;
   context_win32->start_y = y_root;
   context_win32->last_x = context_win32->start_x;
index 9b626e2ad19cbf0e101ce9bd10c77154a4eba50e..1f9acd257f623c5f8b384623b70de447c7afeb12 100644 (file)
@@ -2101,10 +2101,11 @@ GdkDragContext *
 _gdk_x11_window_drag_begin (GdkWindow         *window,
                             GdkDevice         *device,
                             GdkContentFormats *formats,
-                            gint               x_root,
-                            gint               y_root)
+                            gint               dx,
+                            gint               dy)
 {
   GdkDragContext *context;
+  int x_root, y_root;
 
   context = (GdkDragContext *) g_object_new (GDK_TYPE_X11_DRAG_CONTEXT,
                                              "display", gdk_window_get_display (window),
@@ -2120,6 +2121,9 @@ _gdk_x11_window_drag_begin (GdkWindow         *window,
   context->actions = 0;
 
   gdk_drag_context_set_device (context, device);
+  gdk_device_get_position (device, &x_root, &y_root);
+  x_root += dx;
+  y_root += dy;
 
   GDK_X11_DRAG_CONTEXT (context)->start_x = x_root;
   GDK_X11_DRAG_CONTEXT (context)->start_y = y_root;
index e613a5c1dd23909e0d278fee63ee5ffab6fe37b9..e969a3702c3733067ca5b9e9a915b5ddce0e23b9 100644 (file)
@@ -1060,7 +1060,7 @@ gtk_drag_begin_internal (GtkWidget          *widget,
   GtkWidget *ipc_widget;
   GdkDevice *pointer, *keyboard;
   GdkWindow *ipc_window;
-  int start_x, start_y;
+  int dx, dy;
   GdkAtom selection;
 
   pointer = keyboard = NULL;
@@ -1106,21 +1106,37 @@ gtk_drag_begin_internal (GtkWidget          *widget,
       GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
       gtk_widget_translate_coordinates (widget, toplevel,
                                         x, y, &x, &y);
-      gdk_window_get_root_coords (gtk_widget_get_window (toplevel),
-                                  x, y, &start_x, &start_y);
+      gdk_window_get_device_position (gtk_widget_get_window (toplevel),
+                                      pointer,
+                                      &dx, &dy,
+                                      NULL);
+      dx -= x;
+      dy -= y;
     }
   else if (event && gdk_event_get_event_type (event) == GDK_MOTION_NOTIFY)
     {
-      double x, y;
+      double ex, ey;
+      GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
 
-      gdk_event_get_root_coords (event, &x, &y);
-      start_x = (int)x;
-      start_y = (int)y;
+      gdk_event_get_coords (event, &ex, &ey);
+      x = ex;
+      y = ey;
+      gtk_widget_translate_coordinates (widget, toplevel,
+                                        x, y, &x, &y);
+      gdk_window_get_device_position (gtk_widget_get_window (toplevel),
+                                      pointer,
+                                      &dx, &dy,
+                                      NULL);
+      dx -= x;
+      dy -= y;
     }
   else
-    gdk_device_get_position (pointer, &start_x, &start_y);
+    {
+      dx = 0;
+      dy = 0;
+    }
 
-  context = gdk_drag_begin (ipc_window, pointer, target_list, start_x, start_y);
+  context = gdk_drag_begin (ipc_window, pointer, target_list, dx, dy);
 
   if (!gdk_drag_context_manage_dnd (context, ipc_window, actions))
     {